Skip to main content

Try Catch

System.Activities.Statements.TryCatch

The "Exception - Try Catch" activity in AutomatR is a fundamental component of exception handling, allowing users to create structured blocks for handling exceptions in a controlled manner. This activity helps manage errors gracefully, providing a way to execute specific actions when exceptions occur within a designated "Try" block.

Properties

NameDescription
Misc
Display NameThe display name of the activity. A display name is automatically generated when you indicate a target.

The "Try Catch" activity doesn't have additional properties beyond the display name. However, it is crucial in establishing a structured framework for handling exceptions in AutomatR workflows.

How it works: The "Exception - Try Catch" activity consists of two main components:

  • Try Block: This is the area where you place the activities that might raise exceptions. If an exception occurs within the "Try" block, the workflow transitions to the associated "Catch" block(s).

  • Catch Block(s): These are one or more blocks where you define the actions to be taken when specific exceptions occur. Each "Catch" block is associated with a specific type of exception. If an exception of the specified type occurs in the "Try" block, the workflow transitions to the corresponding "Catch" block for handling.

Here's a basic example of how the "Exception - Try Catch" activity is structured:

Try
// Activities that might raise exceptions
ReadFileContent("file.txt")
Catch System.IO.FileNotFoundException
// Handle the file not found exception
LogMessage("The specified file was not found.")
Catch System.IO.IOException
// Handle other IO-related exceptions
LogMessage("An IO error occurred.")
Catch System.Exception
// Handle any other unexpected exceptions
LogMessage("An unexpected error occurred.")
End Try

In this example, the "Try" block contains activities that might read the content of a file, and specific "Catch" blocks handle different types of exceptions that might occur during file reading. The last "Catch" block, with System.Exception, serves as a catch-all for unexpected exceptions.

By utilizing the "Exception - Try Catch" activity, users can create resilient and robust workflows that gracefully handle errors, providing a mechanism to recover, log, or notify users about unexpected conditions.